﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ArtMath.Window
{
    public partial class PrintSketchpadsWindow : Form
    {
        public PrintSketchpadsWindow(IEnumerable<SketchPad> pads)
        {
            InitializeComponent();
            Dictionary<string, ListViewGroup> groups = new Dictionary<string, ListViewGroup>();
            foreach (SketchPad item in pads)
            {
                if (!groups.TryGetValue(item.Document.Title, out ListViewGroup gp))
                {
                    gp = new ListViewGroup(item.Document.Title);
                    lvPads.Groups.Add(gp);
                    groups.Add(item.Document.Title, gp);
                }
                imageList1.Images.Add(item.GetThumbNail());
                ListViewItem lvItem = new ListViewItem(item.Name)
                {
                    ImageIndex = imageList1.Images.Count - 1,
                    Group = gp,
                    Tag = item,
                };
                lvPads.Items.Add(lvItem);
            }
        }
        public SketchPad[] CheckedSketchpads
        {
            get
            {
                SketchPad[] pads = new SketchPad[lvPads.CheckedItems.Count];
                for (int i = 0; i < pads.Length; i++)
                {
                    pads[i] = lvPads.CheckedItems[i].Tag as SketchPad;
                }
                return pads;
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void lvPads_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            btnOK.Enabled = lvPads.CheckedItems.Count > 0;
        }
    }
}
